<%@LANGUAGE="JSCRIPT" CODEPAGE="65001"%>
<%
//====== Security Code OUTPUT ================================
// Copyright 2005 SiC. All Rights Reserved.
// Last Update: 2005-04-20 12:31:28
//============================================================

// Disable Browser cache
Response.Expires = -1;
Response.AddHeader("Pragma","no-cache");
Response.AddHeader("Cache-Control","no-cache");
Response.Buffer = true;

// Call Generate Security Code Function
Response.ContentType = "image/bmp";
genCodeImage(Session("lbsSecurityCode"));
%>
<script language="VBScript" runAt="server">
'========================================================
' Security Code Image Output Function
'--------------------------------------------------------
' Original Author: Layen
' E-mail: support@ssaw.net
' Modified By SiC, 2005-03-23 14:09:14
'========================================================
Function genCodeImage(strCode)

  Const cOdds = 3 'Appear ratio of random noise dots
  Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

  Randomize

  'Color Data ------------------
  Dim vColorData(2)
  vColorData(0) = ChrB(0) & ChrB(0) & ChrB(0) 'Foreground - RGB Color
  vColorData(1) = ChrB(255) & ChrB(255) & ChrB(255) 'Background
  vColorData(2) = ChrB(198) & ChrB(198) & ChrB(198) 'Background lines & Noise dots

  'Get codes in Session object -------------------------
  Dim vCode(4)
  For intChar = 0 To 3
    vCode(intChar) = InStr(cCode,Mid(strCode, intChar+1, 1))-1
  Next

  'Binary data of code characters -------------------------
  Dim vNumberData(35)
  vNumberData(0) = "1110000111110011101111011110111101011011110101101111011010111101101011110111101111011100111110000111"
  vNumberData(1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
  vNumberData(2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
  vNumberData(3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
  vNumberData(4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
  vNumberData(5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
  vNumberData(6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
  vNumberData(7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
  vNumberData(8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
  vNumberData(9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
  vNumberData(10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011111011101111000100011"
  vNumberData(11) = "1000000111110111101111011110111101110111110000111111011101111101111011110111101111011110111000000111"
  vNumberData(12) = "1110000011110111101110111110111011111111101111111110111111111011111111101111101111011101111110001111"
  vNumberData(13) = "1000001111110111011111011110111101111011110111101111011110111101111011110111101111011101111000001111"
  vNumberData(14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"
  vNumberData(15) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011111111000111111"
  vNumberData(16) = "1110000111110111011110111101111011111111101111111110111111111011100011101111011111011101111110001111"
  vNumberData(17) = "1000100011110111011111011101111101110111110000011111011101111101110111110111011111011101111000100011"
  vNumberData(18) = "1100000111111101111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
  vNumberData(19) = "1110000011111110111111111011111111101111111110111111111011111111101111111110111110111011111000011111"
  vNumberData(20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111111011101111000100011"
  vNumberData(21) = "1000111111110111111111011111111101111111110111111111011111111101111111110111111111011110111000000011"
  vNumberData(22) = "1000100011110010011111001001111100100111110101011111010101111101010111110101011111010101111001010011"
  vNumberData(23) = "1000100011110011011111001101111101010111110101011111010101111101100111110110011111011001111000110111"
  vNumberData(24) = "1110001111110111011110111110111011111011101111101110111110111011111011101111101111011101111110001111"
  vNumberData(25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111011111111000111111"
  vNumberData(26) = "1110001111110111011110111110111011111011101111101110111110111011111011101001101111011001111110001011"
  vNumberData(27) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111011101111000110011"
  vNumberData(28) = "1110000011110111101111011110111101111111111001111111111001111111111011110111101111011110111100000111"
  vNumberData(29) = "1000000011101101101111110111111111011111111101111111110111111111011111111101111111110111111110001111"
  vNumberData(30) = "1000100011110111011111011101111101110111110111011111011101111101110111110111011111011101111110001111"
  vNumberData(31) = "1000100011110111011111011101111101110111111010111111101011111110101111111010111111110111111111011111"
  vNumberData(32) = "1001010011110101011111010101111101010111110101011111001001111110101111111010111111101011111110101111"
  vNumberData(33) = "1000100011110111011111101011111110101111111101111111110111111110101111111010111111011101111000100011"
  vNumberData(34) = "1000100011110111011111011101111110101111111010111111110111111111011111111101111111110111111110001111"
  vNumberData(35) = "1100000011110111011111111101111111101111111110111111110111111111011111111011111111101110111100000011" 
  
  'Output BMP Header (14 bytes) ----------------
  Response.BinaryWrite ChrB(66) & ChrB(77) 'Signature "BM"
  Response.BinaryWrite ChrB(214) & ChrB(5) & ChrB(0) & ChrB(0) 'File Size (214+5*256=1494 bytes)
  Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0)
  Response.BinaryWrite ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0) 'File offset to Raster Data (14+40)
                       
  'Output BMP Image Info Header (40 bytes) -----------------
  Response.BinaryWrite ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) 'Size of Info Header (=40)
  Response.BinaryWrite ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) 'Image Width
  Response.BinaryWrite ChrB(12) & ChrB(0) & ChrB(0) & ChrB(0) 'Image Height
  Response.BinaryWrite ChrB(1) & ChrB(0) 'Plane Count (=1)
  Response.BinaryWrite ChrB(24) & ChrB(0) 'Color Depth (We must use 24bit to avoid complex palette calculation)
  Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) ' Compression (=0, not compress)
  Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) 'Image Size (=0, valid when compression=0)
  Response.BinaryWrite ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) 'Horizontal resolution: Pixels/meter
  Response.BinaryWrite ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) 'Vertical resolution: Pixels/meter
  Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) 'Actually used colors count
  Response.BinaryWrite ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) 'Number of important colors (=0, all)

  'Output BMP Data Chunk -----------------

  'Draw a blank line
  For intPixel=0 To 39
    Response.BinaryWrite vColorData(2)
  Next

  'Draw main content
  For intLine = 9 To 0 Step -1  'Loop through all lines
    For intChar = 0 To 3  'Loop through all chars
      For intPixel = 1 To 10 'Loop through all pixels of this line of this char
        If Rnd * 99 + 1 < cOdds Then 'Random noise
          Response.BinaryWrite vColorData(2)
        Else
          currentColor=CInt(Mid(vNumberData(vCode(intChar)), intLine * 10 + intPixel, 1))
          If (intLine Mod 2)=0 And currentColor<>0 Then currentColor=2
          Response.BinaryWrite vColorData(currentColor)
        End If
      Next
    Next
  Next
  
  'Draw a blank line
  For intPixel=0 To 39
    Response.BinaryWrite vColorData(1)
  Next

End Function

</script>
